<?php  namespace web\admin\controller;
/**
 * 货品控制器
 * 刘超群
 * 2016年10月10日21:51:07
 */


class Goodslist extends Common{
    //动作
	protected $db;
	public function __construct()
	{
		parent::__construct();
		$this->db = new \system\model\Goods_list();
	}
//	显示数据  进行添加
	public function index(){
		$gid = q('get.gid',0,'intval');
		if (IS_POST){
			if ($this->db->store()){
				message('添加成功',u('index',['gid'=>$gid]),'success');
			}
			message($this->db->getError(),'','error');
		}
//		获取全部数据进行循环把数字转化成文字写入大数组
		$loddata = $this->db->get();
		foreach ($loddata as $k=>$v){
			$combine = explode(',',$v['combine']);
//			p($combine);
			foreach ($combine as $kk=>$vv){
				$combine[$kk] = Db::table('goods_attr')->where('gtid',$vv)->pluck('gtvalue');
//				p($combine[$kk]);
			}
			$loddata[$k]['combine']=$combine;
		}
//		p($loddata);exit;
		//在类型属性中根据class和tid筛选出规格数据
		$tid = Db::table('goods')->where('gid',$gid)->pluck('tid');
		$data = Db::table('typeattr')->where('class',2)->where('tid',$tid)->get();
//		p($data);
		foreach($data as $k=>$v){
			$data[$k]['select']=Db::table('goods_attr')->where('gid',$gid)->where('taid',$v['taid'])->get();
		}
//		p($data);
		View::with('loddata',$loddata);
		View::with('data',$data);
		View::make();
	}
//	删除
	public function del(){
		$glid = q('get.glid',0,'intval');
		$this->db->where('glid',$glid)->delete();
		message('删除成功','','success');
	}
}
